package com.runen.wnhz.runen.ui;

import android.content.Context;
import android.support.multidex.MultiDex;
import android.util.DisplayMetrics;
import android.widget.Toast;

import com.orhanobut.logger.Logger;
import com.runen.wnhz.runen.common.login.Wx.WeiXinUtils;
import com.runen.wnhz.runen.common.utils.Constants;
import com.runen.wnhz.runen.common.utils.DisplayUtil;
import com.runen.wnhz.runen.di.component.ApplicationComponent;
import com.runen.wnhz.runen.di.component.DaggerApplicationComponent;
import com.runen.wnhz.runen.di.module.ApplicationModule;
import com.runen.wnhz.runen.di.module.HttpModule;

import org.simple.eventbus.EventBus;

import cn.jpush.android.api.JPushInterface;
import io.rong.imkit.RongIM;

import static com.github.mikephil.charting.charts.Chart.LOG_TAG;


/**
 * Created by saky on 2016/7/5.
 */

public class BaseApplication extends RunEnArApplication {

    ApplicationComponent mAppComponent;

    public static BaseApplication get(Context context) {
        return (BaseApplication) context.getApplicationContext();
    }

    public ApplicationComponent getAppComponent() {

        return mAppComponent;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
        WeiXinUtils.getInstance().regToWx(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mAppComponent
                = DaggerApplicationComponent.builder()
                .applicationModule(new ApplicationModule(this))
                .httpModule(new HttpModule())
                .build();
/*        *//*友盟分享登录*//*
        UMConfigure.init(this,"5b8f3370a40fa317f80002bc"
                ,"umeng",UMConfigure.DEVICE_TYPE_PHONE,"");//58edcfeb310c93091c000be2 5965ee00734be40b580001a0
      *//*  PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
        PlatformConfig.setWeixin("wx45ded9c0b63a0889","6c940d7cdd924baf004111c24fbb0a04");*//*

        UMConfigure.setLogEnabled(true);*/
        /*AR 阿里火星眼*/
        init("24849814","e821e6abd767b5e88b93e4f59c68bfe4");
        RongIM.init(this);
       /* //初始化组件化基础库, 统计SDK/推送SDK/分享SDK都必须调用此初始化接口
        UMConfigure.init(this, "5b7fdda4f29d985a6d00004f", "Umeng", UMConfigure.DEVICE_TYPE_PHONE,
                "31c0344312a584f512f3fb6cf65d4de7");*/
        //注册推送服务
        initPush();
    }

    private void initPush() {
        JPushInterface.setDebugMode(true); 	// 设置开启日志,发布时请关闭日志
        JPushInterface.init(this);     		// 初始化 JPush
    }

    //欢迎页的时候执行
    public void initAppconfig() {
        // 初始化log
        Logger.init(LOG_TAG);

        initDisplayOpinion();

        EventBus.getDefault().register(this);
    }


    private void initDisplayOpinion() {
        DisplayMetrics dm = getResources().getDisplayMetrics();
        DisplayUtil.density = dm.density;
        DisplayUtil.densityDPI = dm.densityDpi;
        DisplayUtil.screenWidthPx = dm.widthPixels;
        DisplayUtil.screenhightPx = dm.heightPixels;
        DisplayUtil.screenWidthDip = DisplayUtil.px2dp(getApplicationContext(), dm.widthPixels);
        DisplayUtil.screenHightDip = DisplayUtil.px2dp(getApplicationContext(), dm.heightPixels);
    }
}
